export TensorRT_Lib=/home/xd/TensorRT-8.5.1.7.Linux.x86_64-gnu.cuda-11.8.cudnn8.6/TensorRT-8.5.1.7/lib
export TensorRT_Inc=/home/xd/TensorRT-8.5.1.7.Linux.x86_64-gnu.cuda-11.8.cudnn8.6/TensorRT-8.5.1.7/include
export TensorRT_Bin=/home/xd/TensorRT-8.5.1.7.Linux.x86_64-gnu.cuda-11.8.cudnn8.6/TensorRT-8.5.1.7/bin

export CUDA_Lib=/usr/local/cuda/lib64
export CUDA_Inc=/usr/local/cuda/include
export CUDA_Bin=/usr/local/cuda/bin
export CUDA_HOME=/usr/local/cuda

export CUDNN_Lib=/usr/local/cuda/lib64

# export TensorRT_Lib=${TENSORRT_LIB}
# export TensorRT_Inc=${TENSORRT_INCLUDE}
# export TensorRT_Bin=${TENSORRT_BIN}

# export CUDA_Lib=${CUDA_LIB}
# export CUDA_Inc=${CUDA_INCLUDE}
# export CUDA_Bin=${CUDA_BIN}

# export CUDNN_Lib=${CUDNN_LIB}

# Just used to distinguish the libspconv version, it doesn't affect the version of cuda used by your application
# For CUDA-11.x:    SPCONV_CUDA_VERSION=11.4
# For CUDA-12.x:    SPCONV_CUDA_VERSION=12.6
export SPCONV_CUDA_VERSION=11.4

# resnet50/resnet50int8/swint
export DEBUG_MODEL=onnx_fp16

# fp16/int8
export DEBUG_PRECISION=fp16
export DEBUG_DATA=dump/00000
export USE_Python=ON

# check the configuration path
# clean the configuration status
export ConfigurationStatus=Failed
if [ ! -f "${TensorRT_Bin}/trtexec" ]; then
    echo "Can not find ${TensorRT_Bin}/trtexec, there may be a mistake in the directory you configured."
    return
fi

if [ ! -f "${CUDA_Bin}/nvcc" ]; then
    echo "Can not find ${CUDA_Bin}/nvcc, there may be a mistake in the directory you configured."
    return
fi

echo "=========================================================="
echo "||  MODEL: $DEBUG_MODEL"
echo "||  PRECISION: $DEBUG_PRECISION"
echo "||  DATA: $DEBUG_DATA"
echo "||  USEPython: $USE_Python"
echo "||"
echo "||  TensorRT: $TensorRT_Lib"
echo "||  CUDA: $CUDA_HOME"
echo "||  CUDNN: $CUDNN_Lib"
echo "=========================================================="

BuildDirectory=`pwd`/build

# if [ "$USE_Python" == "ON" ]; then
#     export Python_Inc=`python3 -c "import sysconfig;print(sysconfig.get_path('include'))"`
#     export Python_Lib=`python3 -c "import sysconfig;print(sysconfig.get_config_var('LIBDIR'))"`
#     export Python_Soname=`python3 -c "import sysconfig;import re;print(re.sub('.a', '.so', sysconfig.get_config_var('LIBRARY')))"`
#     echo Find Python_Inc: $Python_Inc
#     echo Find Python_Lib: $Python_Lib
#     echo Find Python_Soname: $Python_Soname
# fi

export PATH=$TensorRT_Bin:$CUDA_Bin:$PATH
export LD_LIBRARY_PATH=$TensorRT_Lib:$CUDA_Lib:$CUDNN_Lib:$BuildDirectory:$LD_LIBRARY_PATH
export PYTHONPATH=$BuildDirectory:$PYTHONPATH
export ConfigurationStatus=Success

if [ -f "scripts/cudasm.sh" ]; then
    echo "Try to get the current device SM"
    . "scripts/cudasm.sh"
    echo "Current CUDA SM: $cudasm"
fi

export CUDASM=$cudasm

echo Configuration done!